package com.yingluo.abacus.boot.core.data.hibernate.utils;

import java.lang.reflect.InvocationTargetException;

import com.yingluo.abacus.boot.core.data.hibernate.dao.CCBaseDao;
import com.yingluo.abacus.boot.core.data.hibernate.dao.IBase;
import org.apache.commons.beanutils.PropertyUtils;
import org.hibernate.SessionFactory;


public class HibernateUtils  {

	public  static  final  String DEFAULT_SESSIONFACTORY="defaultSessionFactory";
	public static CCBaseDao<?,?> getDao(SessionFactory factory , Class<?> boClass){
		return new CCBaseDao(factory,boClass);
	}
	
	public static String getCurrentLoginId(){
		return "";
	}
	public static <T   , P> T copy(Class<T> des,  P ori)
		throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {

	    if(ori==null) return null; 

		T desNew = des.newInstance();
		PropertyUtils.copyProperties(desNew, ori);
		if(desNew instanceof IBase) {
			((IBase)desNew).init();
		}
		return desNew;
	}

}
